<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JsUnit Tests</title>
    <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
    <script language="JavaScript" type="text/javascript" src="../app/jsUnitCore.js"></script>
    <script language="JavaScript" type="text/javascript" src="../../lib/MJ.js"></script>
    <script language="JavaScript" type="text/javascript">
        function testIsPinfu1() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["3m", "4m", "5m", "5m", "6m", "7m",
	                  "2p", "3p", "4p", "6s", "7s", "8s",
			  "3s", "3s"], "6s");
            var agari_pattern = tehai.getAgariPattern();
	    assertTrue(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
        }

        function testIsPinfu2() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["3m", "4m", "5m", "6m", "7m", "8m",
	                  "2p", "3p", "4p", "7s", "8s", "9s",
			  "南", "南"], "9s");
            var agari_pattern = tehai.getAgariPattern();
	    assertTrue(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
        }

        function testIsPinfu3() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["1m", "1m", "2m", "2m", "3m", "3m",
	                  "2s", "3s", "4s", "7s", "8s", "9s",
			  "4m", "4m"], "9s");
            var agari_pattern = tehai.getAgariPattern();
	    assertTrue(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
	    assertTrue(MJ.Hantei._1Han.isPinfu(agari_pattern[1]));
        }

        function testIsPinfu4() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["1m", "2m", "3m", "3m", "4m", "5m",
	                  "2s", "3s", "4s", "7s", "8s", "9s",
			  "1m", "1m"], "9s");
            var agari_pattern = tehai.getAgariPattern();
	    assertTrue(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
        }

        function testIsPinfu5() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["1m", "1m", "1m", "3m", "4m", "5m",
	                  "2s", "3s", "4s", "7s", "8s", "9s",
			  "9m", "9m"], "9s");
            var agari_pattern = tehai.getAgariPattern();
	    assertFalse(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
        }

        function testIsPinfu6() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["2m", "2m", "3m", "3m", "4m", "4m",
	                  "5s", "5s", "6s", "6s", "7s", "7s",
			  "北", "北"], "7s");
            var agari_pattern = tehai.getAgariPattern();

            // 七対子系の場合はいっぱいパターンが生成される
            assert(agari_pattern.length >= 2);

            // 一個でも成立すればOK
            var ok = false;
            for (var i = 0; i < agari_pattern.length; i++) {
                if (MJ.Hantei._1Han.isPinfu(agari_pattern[i])) {
                    ok = true;
                    break;
                }
            }

	    assertTrue(ok);
        }

        function testIsPinfu7() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["1m", "2m", "3m", "3m", "4m", "5m",
	                  "2s", "3s", "4s", "7s", "8s", "9s",
			  "白", "白"], "9s");
            var agari_pattern = tehai.getAgariPattern();
	    assertFalse(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
        }

        function testIsPinfu8() {
            var tehai = new MJ.Tehai();
	    tehai.addAll(["4m", "4m", "2s", "2s", "3s", "3s",
	                  "4s", "4s", "5s", "5s", "8s", "8s",
			  "白", "白"], "2s");
            var agari_pattern = tehai.getAgariPattern();
            assertEquals(1, agari_pattern.length);
            assertTrue(agari_pattern[0].tehai.is_chiitoi);
            assertFalse(MJ.Hantei._1Han.isPinfu(agari_pattern[0]));
        }
    </script>
</head>

<body>
<h1>MJ Tests</h1>

<p>This page contains tests for the JsUnit Framework. To see them, take a look at the source.</p>
</body>
</html>
